//
//  WelcomeViewController.swift
//  Weibo
//
//  Created by 孙成宇 on 15/11/29.
//  Copyright © 2015年 mac. All rights reserved.
//

import UIKit

class WelcomeViewController: UIViewController {
    override func loadView() {
        view  = backImage
    }
    override func viewDidLoad() {
        super.viewDidLoad()
   setUp()
        
         iconImage.sd_setImageWithURL(userAccountViewModel().headImageURL, placeholderImage: UIImage(named: "avatar_default_big"))
        
        
        
        
       
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        
        startAnimation()
        
    }
    
    private func startAnimation(){
    
    let offfset = -screenH + 180
        iconImage.snp_updateConstraints { (make) -> Void in
            make.bottom.equalTo(self.view.snp_bottom).offset(offfset)
        }
        
    UIView.animateWithDuration(1.2, delay: 0, usingSpringWithDamping: 0.9, initialSpringVelocity: 9.8, options: [], animations: { () -> Void in
        self.view.layoutIfNeeded()
        
        
        
        
        
        
        }) { (_) -> Void in
        
            
            
           NSNotificationCenter.defaultCenter().postNotificationName(WBSwitchRootVCNotification, object: "Welcome")
        }
    
    }
    
    

    private func setUp() {
        view.addSubview(iconImage)
        view.addSubview(welcomeLabel)
    
    iconImage.snp_makeConstraints { (make) -> Void in
        make.centerX.equalTo(view.snp_centerX)
        make.bottom.equalTo(view.snp_bottom).offset(-180)
        
        }
        
        
        welcomeLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconImage.snp_bottom).offset(16)
            make.centerX.equalTo(iconImage.snp_centerX)
        }
        
        
        iconImage.layer.cornerRadius = 45
        iconImage.layer.masksToBounds = true
        

    
    }
    
    
    
    //懒加载子视图
    private lazy var backImage: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    //头像视图
    private lazy var iconImage: UIImageView = UIImageView()
    
    //欢迎文本
    private lazy var welcomeLabel: UILabel = UILabel(title: (userAccountViewModel().userName ?? "") + " 欢迎归来", fontSize: 19)

    
}
